package com.teacher.system.service;

import com.teacher.system.dao.TeacherDao;
import com.teacher.system.entity.Teacher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeacherService {

    @Resource
    private TeacherDao teacherDao;

    /**
     * 修改会传递id值，新增不会（新增和修改用一个save方法）
     * @param teacher
     */
    public void save(Teacher teacher) {
        teacherDao.save(teacher);
    }

    /**
     * 删除
     * @param id
     */
    public void del(Long id) {
        teacherDao.deleteById(id);
    }

    /**
     * 根据id查询教师
     * @param id
     * @return
     */
    public Teacher findById(Long id) {
        return teacherDao.findById(id).orElse(null);
    }

    public List<Teacher> findAll (){
        return teacherDao.findAll();
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    public Page<Teacher> findPage(Integer pageNum, Integer pageSize, String name) {
        PageRequest request = PageRequest.of(pageNum-1, pageSize);
        return teacherDao.findNameLike(name,request);
    }

}













